#include<bits/stdc++.h>
#define MAXN 200005
using namespace std;
long long tot;
long long ans;
int a[MAXN];

inline void dfs(int n,int cnt,string s)
{

    if(cnt == n)
    {

        for(int i = 0;i < n;i++)
        {

            for(int j = i - 1;j >= 0;j--)
            {

                if(s[i] == s[j])
                {
                    tot += a[i + 1] == a[j + 1] ? a[i + 1] : 0;
                    break;
                }

            }

        }

        ans = max(ans,tot);
        tot = 0;
        return;
    }

    dfs(n,cnt + 1,s + "0");
    dfs(n,cnt + 1,s + "1");
    return;
}

int main()
{

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);

    int t;
    scanf("%d",&t);

    for(int i = 1;i <= t;i++)
    {
        int n;
        scanf("%d",&n);

        for(int j = 1;j <= n;j++) {scanf("%d",&a[j]);}

        ans = 0;
        dfs(n,0,"");
        printf("%lld\n",ans);
    }

    fclose(stdin);
    fclose(stdout);

    return 0;
}
